//
//  UserCenterViewController.m
//  Consume100
//
//  Created by eliot on 16/3/22.
//  Copyright © 2016年 aleven. All rights reserved.
//

#import "UserCenterViewController.h"
#import "MyImageTableViewCell.h"
#import "SettingViewController.h"
#import "UserInfoViewController.h"
#import "GoldRecordTableViewController.h"
#import "MyAssetsViewController.h"
#import "MyTeamViewController.h"
#import "CooperateViewController.h"
#import "ConsumeDetailViewController.h"
#import "MakeExchageHistoryTableViewController.h"
#import "PersonPurchasesHistoryViewController.h"
#import "MyParnerViewController.h"
#import "CashHomeViewController.h"
@interface UserCenterViewController ()<UITableViewDataSource, UITableViewDelegate>


@property (weak, nonatomic) IBOutlet UITableView *tableVIew;

@end

@implementation UserCenterViewController

- (void)viewWillAppear:(BOOL)animated {
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationController.navigationBar.barTintColor = [UIColor blackColor];
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
    self.navigationController.navigationBar.translucent = NO;
    
    self.tableVIew.delegate = self;
    self.tableVIew.dataSource = self;
    [self.tableVIew registerNib:[UINib nibWithNibName:@"MyImageTableViewCell" bundle:nil] forCellReuseIdentifier:@"imageCell"];
    self.tableVIew.tableFooterView = [[UIView alloc] init];
    self.tableVIew.backgroundColor = [UIColor colorWithRed:232/255.0 green:233/255.0 blue:232/255.0 alpha:1];
    UIBarButtonItem *btn = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"icon_setting"] style:UIBarButtonItemStylePlain target:self action:@selector(clickSetingBtn)];
    self.navigationItem.rightBarButtonItem = btn;
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:254/255.0 green:154/255.0 blue:37/255.0 alpha:1];
    self.view.backgroundColor = [UIColor colorWithRed:232/255.0 green:233/255.0 blue:232/255.0 alpha:1];
    
}

//点击右上角设置按钮
- (void)clickSetingBtn {
    SettingViewController *vc = [SettingViewController CreatSettingViewController];
    [self creatNav:vc];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

//创建模态导航控制器
-(void)creatNav:(UIViewController *)view{
    
    UINavigationController *nav=[[UINavigationController alloc] initWithRootViewController:view];
    nav.navigationBar.barTintColor = [UIColor colorWithRed:254/255.0 green:154/255.0 blue:37/255.0 alpha:1];
    view.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icon_back"] style:UIBarButtonItemStylePlain target:self action:@selector(dismiss)];
    [self.navigationController pushViewController:view animated:YES];
    self.tabBarController.tabBar.hidden = YES;
}

- (void)dismiss {
    [self.navigationController popViewControllerAnimated:YES];
    self.tabBarController.tabBar.hidden = NO;
}



#pragma mark - tableView (tableViewDelegate/tableViewDataSource)

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 4;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    switch (section) {
        case 0:
            return 1;
            break;
        case 1:
            return 3;
            break;
        case 2:
            return 3;
            break;
        default:
            return 3;
            break;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    switch (indexPath.section) {
        case 0:
        {
            MyImageTableViewCell *imagecell = [tableView dequeueReusableCellWithIdentifier:@"imageCell" forIndexPath:indexPath];
            imagecell.headerIV.layer.cornerRadius = 45;
            imagecell.headerIV.layer.masksToBounds = YES;
            UIImageView *iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_arrows"]];
            iv.frame = CGRectMake(0, 0, 12, 12);
            iv.contentMode = UIViewContentModeScaleAspectFit;
            imagecell.accessoryView = iv;
            imagecell.selectionStyle = UITableViewCellSelectionStyleNone;
            return imagecell;
        
        }
            break;
        case 1:
        {
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
            if (!cell) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
                
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            UIImageView *iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_arrows"]];
            iv.frame = CGRectMake(0, 0, 12, 12);
            iv.contentMode = UIViewContentModeScaleAspectFit;
            cell.accessoryView = iv;
            if (indexPath.row == 0) {
                cell.imageView.image = [UIImage imageNamed:@"icon_maidan"];
                cell.textLabel.text = @"消费订单";
            }
            if (indexPath.row == 1) {
                cell.imageView.image = [UIImage imageNamed:@"icon_HGJL"];
                cell.textLabel.text = @"换购记录";
            }
            if (indexPath.row == 2) {
                cell.imageView.image = [UIImage imageNamed:@"icon_ZGJL"];
                cell.textLabel.text = @"众购记录";
            }
            return cell;
            
        }
            break;
        case 2:
        {
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
            cell.accessoryType = UITableViewCellAccessoryDetailButton;
            if (!cell) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
                
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            UIImageView *iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_arrows"]];
            iv.frame = CGRectMake(0, 0, 12, 12);
            iv.contentMode = UIViewContentModeScaleAspectFit;
            cell.accessoryView = iv;
            if (indexPath.row == 0) {
                cell.imageView.image = [UIImage imageNamed:@"icon_WDZC"];
                cell.textLabel.text = @"我的资产";
            }else if (indexPath.row == 1) {
                cell.imageView.image = [UIImage imageNamed:@"icon_JBJL"];
                cell.textLabel.text = @"金币记录";
            }else {
                
                cell.imageView.image = [UIImage imageNamed:@"Tab_bar_ME"];
                cell.textLabel.text = @"我的补贴";
            }
            return cell;
            
        }
            break;
            
        default:
        {
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
            cell.accessoryType = UITableViewCellAccessoryDetailButton;
            if (!cell) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
                
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            UIImageView *iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_arrows"]];
            iv.frame = CGRectMake(0, 0, 12, 12);
            iv.contentMode = UIViewContentModeScaleAspectFit;
            cell.accessoryView = iv;
            if (indexPath.row == 0) {
                cell.imageView.image = [UIImage imageNamed:@"icon_FXFL"];
                cell.textLabel.text = @"分享福利";
            }
            if (indexPath.row == 1) {
                cell.imageView.image = [UIImage imageNamed:@"icon_myteam"];
                cell.textLabel.text = @"我的团队";
            }
            if (indexPath.row == 2) {
                cell.imageView.image = [UIImage imageNamed:@"icon_WYHZ"];
                cell.textLabel.text = @"我要合作";
            }
            return cell;
        
        }
            break;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section == 0) {
        return 112;
    }else {
        return 44;
    }
    
}


- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    if (section == 3) {
        return 0;
    }else {
        return 15;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section == 0) {//点击个人信息
        UserInfoViewController *vc = [UserInfoViewController CreatUserInfoViewController];
        [self creatNav:vc];
        
        
    }
    if (indexPath.section == 1) {
        if (indexPath.row == 0) {//点击消费订单
            ConsumeDetailViewController *vc = [ConsumeDetailViewController CreatConsumeDetailViewController];
            [self creatNav:vc];
            
        }
        if (indexPath.row == 1) {//点击换购记录
            MakeExchageHistoryTableViewController *vc = [MakeExchageHistoryTableViewController CreatMakeExchageHistoryTableViewController];
            [self creatNav:vc];
            
        }
        if (indexPath.row == 2) {//点击众购记录
            
            PersonPurchasesHistoryViewController *vc = [PersonPurchasesHistoryViewController CreatPersonPurchasesHistoryViewController];
            [self creatNav:vc];
        }
    }
    if (indexPath.section == 2) {
        if (indexPath.row == 0) {//点击我的资产
            MyAssetsViewController *vc = [MyAssetsViewController CreatMyAssetsViewController];
            [self creatNav:vc];
        }else if (indexPath.row == 1) {//点击金币记录
            GoldRecordTableViewController *vc = [GoldRecordTableViewController CreatGoldRecordTableViewController];
            [self creatNav:vc];
        }else {
            CashHomeViewController *vc = [CashHomeViewController CreatCashHomeViewController];
            [self creatNav:vc];
        }
    }
    if (indexPath.section == 3) {
        if (indexPath.row == 0) {//点击分享福利
            MyParnerViewController *vc = [MyParnerViewController CreatMyParnerViewController];
            [self creatNav:vc];
        }
        if (indexPath.row == 1) {//点击我的团队
            MyTeamViewController *vc = [MyTeamViewController CreatMyTeamViewController];
            [self creatNav:vc];
        }
        if (indexPath.row == 2) {//点击我要合作
            CooperateViewController *vc = [CooperateViewController CreatCooperateViewController];
            [self creatNav:vc];
        }
    }

    
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
